const app = getApp();
const req = require("../../utils/http.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    type:'',
    outTradeNo:'',//订单编号
     showPayPwdInput: false,  //是否展示密码输入层
    refundSecret: '',  //输入的密码
    params:'',
    renovate:'true'
  
  },


  //退款弹框
  drawbackClike(){
    this.setData({
      showPayPwdInput: true //是否展示密码输入层
    })
  },
 
  inputPwd(e){
    let refundSecret = e.detail.value
    this.setData({ refundSecret})
  },
  //关闭支付框
  closePayLayer() {
    this.setData({
      showPayPwdInput: false,  //是否展示密码输入层
    })
  },
  cancelClike(){
    this.setData({
      showPayPwdInput: false,  //是否展示密码输入层
    })
  },
  //退款--确定
  ensureClike(e){
    let t = this
    let { refundSecret, outTradeNo} =t.data 
    let params = { refundSecret, outTradeNo}
    req.wxReq("/api/face/refund","GET",params).then(res=>{
      if (res.data.code==200){
        // 调用打印
        let id = e.currentTarget.dataset.id
        t.print(id)
        wx.showToast({
          title: res.data.message,
          duration:500
        })
        setTimeout(()=>{
          this.setData({
            showPayPwdInput: false,  //是否展示密码输入层
          }) 
      
          let pages = getCurrentPages();
          let prevPage = pages[pages.length - 2];

          prevPage.setData({
            params: this.data.params,
            renovate: this.data.renovate
          })
          wx.navigateBack({
            data: 1
          })  
        },800)
       
      }else{
        wx.showToast({
          title: res.data.message,
          duration: 500,
          icon:'none'
        })
        
      }
    })
  },


  //打印01
  print(e){
    let params={
      orderId: e
    }
    req.wxReq("/api/statistics/printOrder","GET",params).then(res=>{
      if(res.data.code==200){
        wx.showToast({
          title: res.data.message,
          duration:500
        })
      }else{
        wx.showToast({
          title: res.data.message,
          duration: 500,
          icon:'none'
        })
      }
    })
  },
  //打印02
  dayinClike(e){
    let id = e.currentTarget.dataset.id
    this.print(id)
  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let list = JSON.parse(options.details)
    let params = JSON.parse(options.params)
    let profitSharingStatus = '';
    this.setData({
      list,
       profitSharingStatus,
      type: app.globalData.type,
      outTradeNo: options.outTradeNo, // 订单编号
      params
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})